class Solution(object):
    def sortByBits(self, arr):
        arr.sort(key=lambda x: (x.bin_count(), x))
        return arr
